<?php
// Tim'Roster
// Copyright (c) 2011 Nicolas Nallet <aspgic2@gmail.com>
//
// This file is part of Tim'Roster.
//
// Tim'Roster is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Tim'Roster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

$xml_config = simplexml_load_file('config.xml');

include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/data_access/logbook_DA.php');
include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/class/Character.php');


class Logbook {

    const MEMBER_INVITE_TYPE = 1;
    const MEMBER_LEAVE_TYPE = 2;
    const MEMBER_GRADE_CHANGE = 3;

    /**
     * (PHP 5)<br/>
     * Generate a new member type log
     * @param string $char_name
     * @param int $id_guild
     */
    public static function new_member_in_guild($char_name, $id_guild) {
        $logbook_DA = new logbook_DA();
        $text = $char_name.' join us.';
        $logbook_DA->create_logbook_entry(Logbook::MEMBER_INVITE_TYPE, $text, $id_guild);
    }

    /**
     * (PHP 5)<br/>
     * Generate a leaving guild member type log
     * @param string $char_name
     * @param int $id_guild
     */
    public static function member_leave_guild($char_name, $id_guild) {
        $logbook_DA = new logbook_DA();
        $text = $char_name.' leave us.';
        $logbook_DA->create_logbook_entry(Logbook::MEMBER_LEAVE_TYPE, $text, $id_guild);
    }

    /**
     * (PHP 5)<br/>
     * Generate a grade changement type log
     * @param string $char_name
     * @param string $new_grade
     * @param int $id_guild
     */
    public static function member_grade_changed($char_name, $new_grade_id, $id_guild) {
        $logbook_DA = new logbook_DA();
        $text = $char_name.' evolve to the grade '.Guild_Member::get_grade_label($new_grade_id);
        $logbook_DA->create_logbook_entry(Logbook::MEMBER_GRADE_CHANGE, $text, $id_guild);
    }


    /**
     * (PHP 5)<br/>
     * Construct a Logbook instance
     * @param int $guild_id
     */
    public function Logbook($guild_id){
        $this->guild_id = $guild_id;

        $logbook_DA = new logbook_DA();
        $this->log_array = $logbook_DA->get_guild_logbook_entry($guild_id);
    }

    private $guild_id;
    /**
     * (PHP 5)<br/>
     * Get logbook guild id
     * @return int
     */
    public function get_fk_guild_id(){
        return $this->fk_guild_id;
    }

    private $log_array;
    /**
     * (PHP 5)<br/>
     * Get logbook log array
     * @return array of Log
     */
    public function get_log_array(){
        return $this->log_array;
    }

}

class Log {
    /**
     * (PHP 5)<br/>
     * Construct a Log instance
     * @param int $id
     * @param int $type
     * @param string $text
     * @param date $date
     */
    public function Log($id, $type, $text, $date){
        $this->id = $id;
        $this->type = $type;
        $this->text = $text;
        $this->date = $date;
    }

    private $id;
//    public function get_id(){
//        return $this->id;
//    }

    private $type;
    /**
     * (PHP 5)<br/>
     * Get log type
     * @return <type>
     */
    public function get_type(){
        return $this->type;
    }

    private $text;
    /**
     * (PHP 5)<br/>
     * Get log text
     * @return string
     */
    public function get_text(){
        return $this->text;
    }

    private $date;
    /**
     * (PHP 5)<br/>
     * Get log date
     * @return date
     */
    public function get_date(){
        return $this->date;
    }
}




?>
